package com.kantboot.functional.im.dto;

import com.alibaba.fastjson2.JSON;
import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.util.List;

/**
 * 关于push的DTO
 */
@Data
@Accessors(chain = true)
public class FunctionalImPushMessageDTO implements Serializable {

    /**
     * 类型编码，驼峰式命名
     * 单聊 chatOne
     */
    public static final String TYPE_CODE_CHAT_ONE = "chatOne";

    /**
     * 类型编码，驼峰式命名
     * 群聊 chatGroup
     */
    public static final String TYPE_CODE_CHAT_GROUP = "chatGroup";

    /**
     * 类型编码，驼峰式命名
     * 系统消息 system
     */
    public static final String TYPE_CODE_SYSTEM = "system";

    /**
     * 类型编码，驼峰式命名
     * 通知 notification
     */
    public static final String TYPE_CODE_NOTIFICATION = "notification";

    /**
     * 是根据userId还是cid推送
     * userId
     */
    public static final String PUSH_TYPE_CODE_USER_ID = "userId";

    /**
     * 是根据userId还是cid推送
     * cid
     */
    public static final String PUSH_TYPE_CODE_CID = "cid";

    /**
     * 类型编码，驼峰式命名
     * 1.单聊 chatOne
     * 2.群聊 chatGroup
     * 3.系统消息 system
     * 4.通知 notification
     * 也可以由业务自定义
     */
    private String typeCode;

    /**
     * 是根据userId还是cid推送
     */
    private String pushTypeCode;

    /**
     * 用户id
     */
    private Long userId;

    /**
     * 是否强制通知
     */
    private Boolean forceNotification;

    /**
     * 消息标题
     */
    private String title;

    /**
     * 消息内容
     */
    private String content;

    /**
     * 消息ttl
     */
    private Long ttl;


    /**
     * 消息中间件
     */
    @Data
    @Accessors(chain = true)
    public static class Broker implements Serializable {

        /**
         * 发送消息的中间件
         * uniPush
         */
        public static final String CODE_UNI_PUSH = "uniPush";

        /**
         * 发送消息的中间件
         * mqtt
         */
        public static final String CODE_MQTT = "mqtt";

        /**
         * 发送消息的中间件
         * websocket
         */
        public static final String CODE_WEBSOCKET = "websocket";

        /**
         * 状态编码
         * 未发送 notSend
         */
        public static final String STATUS_CODE_NOT_SEND = "notSend";

        /**
         * 状态编码
         * 发送中 sending
         */
        public static final String STATUS_CODE_SENDING = "sending";

        /**
         * 状态编码
         * 发送成功 sendSuccess
         */
        public static final String STATUS_CODE_SEND_SUCCESS = "sendSuccess";

        /**
         * 状态编码
         * 发送失败 sendFail
         */
        public static final String STATUS_CODE_SEND_FAIL = "sendFail";

        /**
         * 状态编码
         * 未被接收 notReceived
         */
        public static final String STATUS_CODE_NOT_RECEIVED = "notReceived";

        /**
         * 状态编码
         * 已被接收 received
         */
        public static final String STATUS_CODE_RECEIVED = "received";

        /**
         * 中间件编码
         */
        private String code;

        /**
         * cid
         */
        private String cid;

        /**
         * 绑定消息
         */
        private Long messageId;

        /**
         * 状态编码，驼峰式命名
         * 1.未发送 notSend
         * 2.发送中 sending
         * 3.发送成功 sendSuccess
         * 4.发送失败 sendFail
         * 5.未被接收 notReceived
         * 6.已被接收 received
         */
        private String statusCode;

        /**
         * 发送失败原因编码
         */
        private String statusFailReasonCode;

    }


    private List<Broker> brokers;

    /**
     * 消息payload
     */
    @Data
    @Accessors(chain = true)
    public static class Payload implements Serializable {

        /**
         * emit
         */
        private String emit;

        /**
         * 消息内容
         */
        private String dataStr;

        /**
         * 消息内容
         */
        private Object data;

        public Payload setData(Object data) {
            if(data == null){
                return this;
            }
            this.data = data;
            this.dataStr = JSON.toJSONString(data);
            return this;
        }

    }

    private Payload payload;


}
